package userController

import (
	"myRbac/models"
	"net/http"

	"github.com/gin-gonic/gin"
)

type CheckAbout struct{}

// @Summary 账户验证
// @Description 输入账户存在性检验
// @Tags 可行验证
// @Accept json
// @Produce json
// @Param account query string true "账户名"
// @Success 200 {object} models.ResultCommon[string] "0"
// @Success 200 {object} models.ResultCommon[string] "1"
// @Router /check/account [get]
func (c CheckAbout) CheckAccount(ctx *gin.Context) {
	account := ctx.Query("account")
	user := &models.User{}
	models.DB.Where("account = ?", account).Find(&user)
	if user.Id == 0 {
		ctx.JSON(http.StatusOK, models.ResultCommon[string]{
			Msg:    "ok",
			Code:   "200",
			Result: "0",
		})
	} else {
		ctx.JSON(http.StatusOK, models.ResultCommon[string]{
			Msg:    "用户名已存在",
			Code:   "200",
			Result: "1",
		})
	}
}
